import publicForm from "@/components/materialDataManage/fromCom.vue"; //弹框form

import formJs from "./regexDetail.js"; //新增弹框配置项
import TableData from "@/components/public/el-table"; //主页面列表
import TableLyout from '@/components/commonPublic/tableLyout.vue'
import publicForm1 from "@/components/materialDataManage/fromCom.vue"; //弹框form
import FormLyout from '@/components/commonPublic/fromLayout.vue'
import messageBox from "@/components/public/messageBox"; //主页面分页

import {
    getSpeciesDataList, //种类
    getSpecificationDataList, //列表页接口
} from "@/api/request.js";

export default {
    props: [
        "dialogVisible",
    ],
    data() {
        return {
            visible: "",
            showMsgBox: false,
            msgTip: "请先选中数据行！",
            msgType: 1,
            isSave: true,
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            materialInfo_config: formJs.materialInfo_config,
            // 列表
            getList: {
                page: 1,
                pageSize: 500,
                fId: ""
                // name: "", //材料种类/名称
                // fVersion: "" //规格型号
            },
            loading: false,
            materialData: [], //种类数据
            tableData: [],
            title: null,
            isLock: false,
            dialogHeight: null,
            activeIndex: "1",
            btnShow: true,
            currentRow: null,
            types: null,
        };
    },
    components: {
        publicForm,
        TableLyout,
        TableData,
        publicForm1,
        FormLyout,
        messageBox
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.btnShow = true
        this.getSpeciesList() //获取种类材料
        this.getHeight();
    },
    methods: {
        confirmMsg() {
            this.showMsgBox = false;
        },
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.5 + "px";
        },
        closeDialog1() {
            this.$emit("close1");
        },
        getSpeciesList() {
            var obj = {
                page: 1,
                pageSize: 500
            }
            getSpeciesDataList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.materialData = []
                        res.data.pageInfo.list.map(item => {
                            if (item.fStatus == 1) {
                                this.materialData.push(item)
                            }
                        })
                        this.getList.fId = this.materialData[0].fVarietyid

                        this.yj_searchForm(this.getList)
                    } else {
                        // this.$message.error(res.msg);
                        return false;
                    }
                })
                .catch(() => {
                    return false;
                });
        },
        rowChange1(val) {
            this.getList.fId = val.fVarietyid;
            this.types = val
            this.yj_searchForm(this.getList)
        },
        // 点击材料
        rowChange(val) {
            this.currentRow = val
            // this.dataFid = val.fId;
        },

        // 获取列表数据
        yj_searchForm(data) {
            var obj = {
                page: data.page,
                pageSize: data.pageSize,
                fId: data.fId
                // name: data.name, //材料种类/名称
                // fVersion: data.fVersion //规格型号
            }
            this.loading = true;
            var that = this;
            getSpecificationDataList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        this.queryCriteriaData = res.data.pageInfo;
                    } else {
                        // this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    // this.$message.error("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },

        yj_saveForm() {
            if (this.types != null) {


                if (this.currentRow != null) {
                    // sonToFather
                    // this.$router.push({
                    //     path: "/rawMaterialManage/entryLedgerText",

                    // });
                    sessionStorage.setItem(
                        "GxEmbedded_secondaryInfo",
                        JSON.stringify({currentRow:this.currentRow,types:this.types})
                    );
                    this.$router.go(-1); // 返回上一个页面
                    // this.$emit('getMateral', this.currentRow,this.types)
                    this.visible = false
                } else {
                    // this.showMsgBox = true;
                    // this.msgTip = "请先选择材料"
                    this.$message.warning({
                        content: '请先选择需要查看的数据',
                        duration: 1000
                    })

                }
            } else {
                // this.showMsgBox = true;
                // this.msgTip = "请先选择材料种类"
                this.$message.warning({
                    content: '请先选择需要查看的数据',
                    duration: 1000
                })
            }
        },

    },
};